package Day04;

import java.util.Random;
import java.util.Scanner;

public class Demo01 {
    //快递柜
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Random r = new Random();
        int[] sum = new int[1000];//数组当成快递柜，取件码就是快递柜的编号
        for (int i = 0; i < sum.length; i++) {
            sum[i] = 0;
        }//值全部弄成零，意味着快递柜空
        while(true){
            //需要排序和查找，所以需要冒泡排序和二分法查找
            System.out.println("====欢迎使用新职课快递柜====");
            System.out.println("请输入您的身份：1-快递员，2-用户");
            int i = sc.nextInt();
            switch (i){
                case 1:{
                    System.out.println("请选择操作：1-存快递 2-删除快递 3-修改快递信息 4-查看所有快递");
                    int b = sc.nextInt();
                    switch (b){
                        case 1:{
                            System.out.println("请输入快递单号：");
                            int d = sc.nextInt();
                            System.out.println("请输入公司名称:");
                            String next = sc.next();
                            int t = r.nextInt(900) + 100;
                            if(sum[t] == 0){
                                sum[t] = d;
                                System.out.println("快递已存入，取件码是:" + t);
                            }else{
                                System.out.println("请输入正确的快递单号");
                            }
                            break;
                        }
                        case 2:{
                            System.out.println("请输入您要删除的快递单号：");
                            int e = sc.nextInt();
                            for (int j = 0; j < sum.length; j++) {
                                if(e == sum[i]){
                                    sum[i] = 0;
                                    System.out.println("删除成功");
                                }else{
                                    System.out.println("没找到该快递");
                                }
                            }
                            break;
                        }
                        case 3:{
                            System.out.println("请输入你要修改的快递单号：");
                            int f = sc.nextInt();
                            for (int j = 0; j < sum.length; j++) {
                                if(f == sum[i]){
                                    System.out.println("请输入新的快递单号：");
                                    int g = sc.nextInt();
                                    for (int l = 0; l < sum.length; l++) {
                                        if(g != sum[l]){
                                            sum[i] = g;
                                            System.out.println("请输入新公司的名称：");
                                            String h = sc.next();
                                            System.out.println("修改成功");
                                        }else{
                                            System.out.println("该快递单号已存在");
                                        }
                                    }
                                }else{
                                    System.out.println("未找到快递");
                                }
                                break;
                            }
                            break;
                        }
                        case 4:{
                            System.out.println("所有快递信息如下：");
                            for (int j = 0; j < sum.length; j++) {
                                if(sum[j] != 0){
                                    System.out.println("快递单号：" + sum[j] + " " + "取件码：" + j);
                                }
                            }
                            break;
                        }
                    }
                    break;
                }
                case 2:{
                    System.out.println("请输入取件码：");
                    int c = sc.nextInt();
                    if(sum[c] != 0){
                        sum[c] = 0;
                        System.out.println("取件成功");
                    }else {
                        System.out.println("找不到该快递");
                    }
                    break;
                }
            }
        }
    }
}
